#include <iostream>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;

int gcnt = 100;

void *ThreadRoutine(void *arg)
{
    const char *threadName = (const char *)arg;
    while (true)
    {
        cout << "I am a new thread" << ", pid: " << getpid() << ", " << threadName << ", gcnt: " << gcnt << ", &gcnt : " << &gcnt << endl;
        gcnt--;
        sleep(1);
    }
}

int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, ThreadRoutine, (void *)"thread 1");

    while (true)
    {
        cout << "I am main thread" << ", pid: " << ", gcnt : " << gcnt << ", &gcnt : " << &gcnt <<getpid() << endl;
        sleep(1);
    }
    return 0;
}
